package com.chendx.store.order.mq.queue;

/**
 * Created by chendx on 2021/9/29.
 */

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 用于生成订单5分钟内未支付的消息推送
 */
@Configuration
public class OrderPayQueueConfig {


    @Bean
    public Exchange orderPayTimerNoticeExchange(){
        return ExchangeBuilder.directExchange("order_timer_notice_exchange").build();
    }

    @Bean
    public Queue orderTimerNoticeQueue(){
        return new Queue("order_timer_notice_queue",true);
    }

    @Bean
    public Queue orderTimerNoticeDelayQueue(){
        return QueueBuilder.durable("order_timer_notice_delay_queue")
                .withArgument("x-dead-letter-exchange","order_timer_notice_exchange")
                .withArgument("x-dead-letter-routing-key","order_timer_notice_queue")
                .build();
    }

    @Bean
    public Binding orderpaybinding(){
        return BindingBuilder.bind(orderTimerNoticeQueue()).
                to(orderPayTimerNoticeExchange()).with("order_timer_notice_queue")
                .noargs();
    }
}
